﻿using ProBugTracker.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using ProBugTracker.Domain;
using Moq;
using ProBugTracker.Core.Interface;
using ProBugTracker.Data.Interface;
using ProBugTracker.Data;
using System.Collections.Generic;

namespace ProBugTracker.Test
{
    [TestClass()]
    public class UserManagerTest
    {
        //private UserManager _target;
        //private Mock<IUserManagerData> _mockUserManagerData;
        //private Mock<IPermissionManagerData> _mockPermissionManagerData;

        //private static DateTime StartDate = DateTime.Parse("2012-01-01");
        //private static DateTime EndDate = DateTime.Parse("2012-12-31");

        //IList<RoleAssignPermission> userPermission = new List<RoleAssignPermission>()
        //{
        //    new RoleAssignPermission(){UserRolePermissionID=1,PermissionName="Read",PermissionStartDate=StartDate,PermissionEndDate=EndDate,Active=true},
        //    new RoleAssignPermission(){UserRolePermissionID=2,PermissionName="Edit",PermissionStartDate=StartDate,PermissionEndDate=EndDate,Active=true},
        //    new RoleAssignPermission(){UserRolePermissionID=3,PermissionName="Delete",PermissionStartDate=StartDate,PermissionEndDate=EndDate,Active=true},
        //};


        //IList<UserAssignRole> userRoleList = new List<UserAssignRole>()
        //{
        //    new UserAssignRole()
        //    {
        //        UserRoleID=1,
        //        RoleName="Administrator",
        //        Startdate=StartDate,
        //        EndDate=EndDate,
        //        PermissionLevel=
        //        new List<RoleAssignPermission>()
        //        {
        //            new RoleAssignPermission(){UserRolePermissionID=1,PermissionName="Read",PermissionStartDate=StartDate,PermissionEndDate=EndDate,Active=true},
        //            new RoleAssignPermission(){UserRolePermissionID=2,PermissionName="Edit",PermissionStartDate=StartDate,PermissionEndDate=EndDate,Active=true},
        //            new RoleAssignPermission(){UserRolePermissionID=3,PermissionName="Delete",PermissionStartDate=StartDate,PermissionEndDate=EndDate,Active=true},
        //        }
        //    }
        //};

        //UserDB userDB = new UserDB()
        //{
        //    ID=1,
        //    FirstName="Erandika",
        //    MiddleName="Sandaruwan",
        //    LastName="Dunusinghe",
        //    UserName="erandika1986",
        //    Email="erandika1986@gmail.com",
        //    Password="password123",
        //    LastChangeDate=StartDate
        //};

        //UserAssignRoleDB userAssignRoleDB = new UserAssignRoleDB()
        //{
        //    UserRoleID=1,
        //    UserID=1,
        //    StartDate = StartDate,
        //    EndDate = EndDate,
        //    Active=true
        //};

        //RoleAssignPermissionDB roleAssignPermissionDB = new RoleAssignPermissionDB()
        //{
        //    UserRoleID=1,
        //    UserPermissionID=1,
        //    PermissionStartDate=StartDate,
        //    PermissionEndDate = EndDate,
        //    Active=true
        //};


        ///// <summary>
        /////A test for AddNewUser for user not null scenario.
        /////</summary>
        //[TestMethod()]
        //public void AddNewUserTestForUserNotNull()
        //{

        //    _mockUserManagerData = new Mock<IUserManagerData>();
        //    _mockPermissionManagerData = new Mock<IPermissionManagerData>();
        //    _target = new UserManager(_mockUserManagerData.Object, _mockPermissionManagerData.Object);
        //    _mockUserManagerData.Setup(x => x.AddNewUser(It.IsAny<UserDB>())).Returns(userDB);
        //    _mockUserManagerData.Setup(x => x.AddNewUserRole(It.IsAny<UserAssignRoleDB>())).Returns(userAssignRoleDB);
        //    _mockPermissionManagerData.Setup(x => x.AddRolePermission(It.IsAny<RoleAssignPermissionDB>())).Returns(roleAssignPermissionDB);

        //    User user = new User()
        //    {
        //        Email = "erandika1986@gmail.com",
        //        FirstName = "Erandika",
        //        MiddleName = "Sandaruwan",
        //        LastName = "Dunusinghe",
        //        Password = "password123",
        //        Role = userRoleList, 
        //        UserID = 1,
        //        UserName = "erandika1986"

        //    };
            
        //    bool expected = true; 
        //    bool actual;
        //    actual = _target.AddNewUser(user);
        //    Assert.AreEqual(expected, actual);
        //}

        ///// <summary>
        /////A test for AddNewUser for user null scenario. 
        /////</summary>
        //[TestMethod()]
        //public void AddNewUserTestForUserNull()
        //{
        //    _mockUserManagerData = new Mock<IUserManagerData>();
        //    _mockPermissionManagerData = new Mock<IPermissionManagerData>();
        //    _target = new UserManager(_mockUserManagerData.Object, _mockPermissionManagerData.Object);
        //    bool expected = false;
        //    bool actual;
        //    actual = _target.AddNewUser(null);
        //    Assert.AreEqual(expected, actual);
        //}

        ///// <summary>
        /////A test for exception scenario. 
        /////</summary>
        //[TestMethod()]
        //[ExpectedException(typeof(NullReferenceException))]
        //public void AddNewUserTestForThrowException()
        //{
        //    _mockUserManagerData = new Mock<IUserManagerData>();
        //    _mockPermissionManagerData = new Mock<IPermissionManagerData>();
        //    _target = new UserManager(_mockUserManagerData.Object, _mockPermissionManagerData.Object);

        //    User user = new User()
        //    {
        //        Email = "erandika1986@gmail.com",
        //        FirstName = "Erandika",
        //        MiddleName = "Sandaruwan",
        //        LastName = "Dunusinghe",
        //        Password = "password123",
        //        Role = userRoleList,
        //        UserID = 1,
        //        UserName = "erandika1986"

        //    };

        //    bool actual;
        //    actual = _target.AddNewUser(user);
        //}

        ///// <summary>
        /////A test for EditNewUser valid user scenario.
        /////</summary>
        //[TestMethod()]
        //public void EditNewUserTestForValidUser()
        //{
        //    _mockUserManagerData = new Mock<IUserManagerData>();
        //    _mockPermissionManagerData = new Mock<IPermissionManagerData>();
        //    _target = new UserManager(_mockUserManagerData.Object, _mockPermissionManagerData.Object);
        //    _mockUserManagerData.Setup(x => x.EditNewUser(It.IsAny<UserDB>())).Returns(true);

        //    User user = new User()
        //    {
        //        Email = "erandika1986@gmail.com",
        //        FirstName = "Erandika",
        //        MiddleName = "Sandaruwan",
        //        LastName = "Dunusinghe",
        //        Password = "password123",
        //        Role = userRoleList,
        //        UserID = 1,
        //        UserName = "erandika1986"

        //    };

        //    bool expected = true;
        //    bool actual;
        //    actual = _target.EditNewUser(user);
        //    Assert.AreEqual(expected, actual);
        //}

        ///// <summary>
        /////A test for EditNewUser user null scenario.
        /////</summary>
        //[TestMethod()]
        //public void EditNewUserTestForNullUser()
        //{
        //    _mockUserManagerData = new Mock<IUserManagerData>();
        //    _mockPermissionManagerData = new Mock<IPermissionManagerData>();
        //    _target = new UserManager(_mockUserManagerData.Object, _mockPermissionManagerData.Object);
        //    bool expected = false;
        //    bool actual;
        //    actual = _target.EditNewUser(null);
        //    Assert.AreEqual(expected, actual);
        //}


        ///// <summary>
        /////A test for DeleteUser for valid user id
        /////</summary>
        //[TestMethod()]
        //public void DeleteUserTestForValidUserID()
        //{
        //    _mockUserManagerData = new Mock<IUserManagerData>();
        //    _mockPermissionManagerData = new Mock<IPermissionManagerData>();
        //    _target = new UserManager(_mockUserManagerData.Object, _mockPermissionManagerData.Object);
        //    _mockUserManagerData.Setup(x => x.DeleteUser(It.IsAny<int>())).Returns(true);
        //    bool expected = true;
        //    bool actual;
        //    actual = _target.DeleteUser(1);
        //    Assert.AreEqual(expected, actual);

        //}


        ///// <summary>
        /////A test for DeleteUser for invalid user id
        /////</summary>
        //[TestMethod()]
        //public void DeleteUserTestForInvalidUserID()
        //{
        //    _mockUserManagerData = new Mock<IUserManagerData>();
        //    _mockPermissionManagerData = new Mock<IPermissionManagerData>();
        //    _target = new UserManager(_mockUserManagerData.Object, _mockPermissionManagerData.Object);
        //    bool expected = false;
        //    bool actual;
        //    actual = _target.DeleteUser(1);
        //    Assert.AreEqual(expected, actual);

        //}

        ///// <summary>
        /////A test for AddNewUserRole for Valid data set.
        /////</summary>
        //[TestMethod()]
        //public void AddNewUserRoleTestForValidDataSet()
        //{
        //    _mockUserManagerData = new Mock<IUserManagerData>();
        //    _mockPermissionManagerData = new Mock<IPermissionManagerData>();
        //    _target = new UserManager(_mockUserManagerData.Object, _mockPermissionManagerData.Object);
        //    _mockUserManagerData.Setup(x => x.AddNewUserRole(It.IsAny<UserAssignRoleDB>())).Returns(userAssignRoleDB);


        //    bool expected = true; 
        //    bool actual;
        //    actual = _target.AddNewUserRole(1, 1, StartDate, EndDate);
        //    Assert.AreEqual(expected, actual);
        //}


        ///// <summary>
        /////A test for AddNewUserRole for invalid data set.
        /////</summary>
        //[TestMethod()]
        //public void AddNewUserRoleTestForInvalidDataSet()
        //{
        //    _mockUserManagerData = new Mock<IUserManagerData>();
        //    _mockPermissionManagerData = new Mock<IPermissionManagerData>();
        //    _target = new UserManager(_mockUserManagerData.Object, _mockPermissionManagerData.Object);

        //    bool expected = false;
        //    bool actual;
        //    actual = _target.AddNewUserRole(-10, 1, StartDate, EndDate);
        //    Assert.AreEqual(expected, actual);
        //}

        ///// <summary>
        /////A test for RemoveUserRole for valid input parameter.
        /////</summary>
        //[TestMethod()]
        //public void RemoveUserRoleTestForValidInputParameters()
        //{
        //    _mockUserManagerData = new Mock<IUserManagerData>();
        //    _mockPermissionManagerData = new Mock<IPermissionManagerData>();
        //    _target = new UserManager(_mockUserManagerData.Object, _mockPermissionManagerData.Object);
        //    _mockUserManagerData.Setup(x => x.RemoveUserRole(It.IsAny<int>(), It.IsAny<int>())).Returns(true);
        //    int userID = 1; 
        //    int roleID = 1; 
        //    bool expected = true;
        //    bool actual;
        //    actual = _target.RemoveUserRole(userID, roleID);
        //    Assert.AreEqual(expected, actual);
 
        //}

        ///// <summary>
        /////A test for RemoveUserRole for Invalid input parameter.
        /////</summary>
        //[TestMethod()]
        //public void RemoveUserRoleTestForInValidInputParameters()
        //{
        //    _mockUserManagerData = new Mock<IUserManagerData>();
        //    _mockPermissionManagerData = new Mock<IPermissionManagerData>();
        //    _target = new UserManager(_mockUserManagerData.Object, _mockPermissionManagerData.Object);
        //    _mockUserManagerData.Setup(x => x.RemoveUserRole(It.IsAny<int>(), It.IsAny<int>())).Returns(true);
        //    int userID = 0;
        //    int roleID = 0;
        //    bool expected = false;
        //    bool actual;
        //    actual = _target.RemoveUserRole(userID, roleID);
        //    Assert.AreEqual(expected, actual);

        //}

        ///// <summary>
        /////A test for FindAllActiveUsers
        /////</summary>
        //[TestMethod()]
        //public void FindAllActiveUsersTest()
        //{
        //    IUserManagerData userManagerData = null; // TODO: Initialize to an appropriate value
        //    IPermissionManagerData permissionManagerData = null; // TODO: Initialize to an appropriate value
        //    UserManager target = new UserManager(userManagerData, permissionManagerData); // TODO: Initialize to an appropriate value
        //    IList<User> expected = null; // TODO: Initialize to an appropriate value
        //    IList<User> actual;
        //    actual = target.FindAllActiveUsers();
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("Verify the correctness of this test method.");
        //}

        ///// <summary>
        /////A test for FindAllInactiveUsers
        /////</summary>
        //[TestMethod()]
        //public void FindAllInactiveUsersTest()
        //{
        //    IUserManagerData userManagerData = null; // TODO: Initialize to an appropriate value
        //    IPermissionManagerData permissionManagerData = null; // TODO: Initialize to an appropriate value
        //    UserManager target = new UserManager(userManagerData, permissionManagerData); // TODO: Initialize to an appropriate value
        //    IList<User> expected = null; // TODO: Initialize to an appropriate value
        //    IList<User> actual;
        //    actual = target.FindAllInactiveUsers();
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("Verify the correctness of this test method.");
        //}

        ///// <summary>
        /////A test for FindUserByID
        /////</summary>
        //[TestMethod()]
        //public void FindUserByIDTest()
        //{
        //    IUserManagerData userManagerData = null; // TODO: Initialize to an appropriate value
        //    IPermissionManagerData permissionManagerData = null; // TODO: Initialize to an appropriate value
        //    UserManager target = new UserManager(userManagerData, permissionManagerData); // TODO: Initialize to an appropriate value
        //    int userID = 0; // TODO: Initialize to an appropriate value
        //    User expected = null; // TODO: Initialize to an appropriate value
        //    User actual;
        //    actual = target.FindUserByID(userID);
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("Verify the correctness of this test method.");
        //}

        ///// <summary>
        /////A test for FindUserByUserName
        /////</summary>
        //[TestMethod()]
        //public void FindUserByUserNameTest()
        //{
        //    IUserManagerData userManagerData = null; // TODO: Initialize to an appropriate value
        //    IPermissionManagerData permissionManagerData = null; // TODO: Initialize to an appropriate value
        //    UserManager target = new UserManager(userManagerData, permissionManagerData); // TODO: Initialize to an appropriate value
        //    string userName = string.Empty; // TODO: Initialize to an appropriate value
        //    User expected = null; // TODO: Initialize to an appropriate value
        //    User actual;
        //    actual = target.FindUserByUserName(userName);
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("Verify the correctness of this test method.");
        //}

        ///// <summary>
        /////A test for FindUserByFirstName
        /////</summary>
        //[TestMethod()]
        //public void FindUserByFirstNameTest()
        //{
        //    IUserManagerData userManagerData = null; // TODO: Initialize to an appropriate value
        //    IPermissionManagerData permissionManagerData = null; // TODO: Initialize to an appropriate value
        //    UserManager target = new UserManager(userManagerData, permissionManagerData); // TODO: Initialize to an appropriate value
        //    string firstName = string.Empty; // TODO: Initialize to an appropriate value
        //    IList<User> expected = null; // TODO: Initialize to an appropriate value
        //    IList<User> actual;
        //    actual = target.FindUserByFirstName(firstName);
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("Verify the correctness of this test method.");
        //}
    }
}
